/*
===============================================================================
                    EntitySpaces 2009 by EntitySpaces, LLC
             Persistence Layer and Business Objects for Microsoft .NET
             EntitySpaces(TM) is a legal trademark of EntitySpaces, LLC
                          http://www.entityspaces.net
===============================================================================
EntitySpaces Version : 2009.2.1214.0
EntitySpaces Driver  : SQL
Date Generated       : 1/26/2010 10:20:34 AM
===============================================================================
*/

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.ComponentModel;
using System.Xml.Serialization;


using EntitySpaces.Core;
using EntitySpaces.Interfaces;
using EntitySpaces.DynamicQuery;


using DotNetNuke.Framework.Providers;


namespace DNNspot.LiveChat.DataModel
{

	[Serializable]
	abstract public class esClientCollection : esEntityCollection
	{
		public esClientCollection()
		{

		}

		protected override string GetCollectionName()
		{
			return "ClientCollection";
		}

		#region Query Logic
		protected void InitQuery(esClientQuery query)
		{
			query.OnLoadDelegate = this.OnQueryLoaded;
			query.es2.Connection = ((IEntityCollection)this).Connection;
		}

		protected bool OnQueryLoaded(DataTable table)
		{
			this.PopulateCollection(table);
			return (this.RowCount > 0) ? true : false;
		}
		
		protected override void HookupQuery(esDynamicQuery query)
		{
			this.InitQuery(query as esClientQuery);
		}
		#endregion
		
		virtual public Client DetachEntity(Client entity)
		{
			return base.DetachEntity(entity) as Client;
		}
		
		virtual public Client AttachEntity(Client entity)
		{
			return base.AttachEntity(entity) as Client;
		}
		
		virtual public void Combine(ClientCollection collection)
		{
			base.Combine(collection);
		}
		
		new public Client this[int index]
		{
			get
			{
				return base[index] as Client;
			}
		}

		public override Type GetEntityType()
		{
			return typeof(Client);
		}
	}



	[Serializable]
	abstract public class esClient : esEntity
	{
		/// <summary>
		/// Used internally by the entity's DynamicQuery mechanism.
		/// </summary>
		virtual protected esClientQuery GetDynamicQuery()
		{
			return null;
		}

		public esClient()
		{

		}

		public esClient(DataRow row)
			: base(row)
		{

		}
		
		#region LoadByPrimaryKey
		public virtual bool LoadByPrimaryKey(System.Int32 clientId)
		{
			if(this.es.Connection.SqlAccessType == esSqlAccessType.DynamicSQL)
				return LoadByPrimaryKeyDynamic(clientId);
			else
				return LoadByPrimaryKeyStoredProcedure(clientId);
		}

		public virtual bool LoadByPrimaryKey(esSqlAccessType sqlAccessType, System.Int32 clientId)
		{
			if (sqlAccessType == esSqlAccessType.DynamicSQL)
				return LoadByPrimaryKeyDynamic(clientId);
			else
				return LoadByPrimaryKeyStoredProcedure(clientId);
		}

		private bool LoadByPrimaryKeyDynamic(System.Int32 clientId)
		{
			esClientQuery query = this.GetDynamicQuery();
			query.Where(query.ClientId == clientId);
			return query.Load();
		}

		private bool LoadByPrimaryKeyStoredProcedure(System.Int32 clientId)
		{
			esParameters parms = new esParameters();
			parms.Add("ClientId",clientId);
			return this.Load(esQueryType.StoredProcedure, this.es.spLoadByPrimaryKey, parms);
		}
		#endregion
		
		
		
		#region Properties
		
		
		public override void SetProperties(IDictionary values)
		{
			foreach (string propertyName in values.Keys)
			{
				this.SetProperty(propertyName, values[propertyName]);
			}
		}

		public override void SetProperty(string name, object value)
		{
			if(this.Row == null) this.AddNew();
			
			esColumnMetadata col = this.Meta.Columns.FindByPropertyName(name);
			if (col != null)
			{
				if(value == null || value is System.String)
				{				
					// Use the strongly typed property
					switch (name)
					{							
						case "PortalId": this.str.PortalId = (string)value; break;							
						case "ClientId": this.str.ClientId = (string)value; break;							
						case "UserId": this.str.UserId = (string)value; break;							
						case "FirstName": this.str.FirstName = (string)value; break;							
						case "LastName": this.str.LastName = (string)value; break;							
						case "Email": this.str.Email = (string)value; break;							
						case "Ip": this.str.Ip = (string)value; break;							
						case "CreatedDate": this.str.CreatedDate = (string)value; break;							
						case "ModifiedDate": this.str.ModifiedDate = (string)value; break;
					}
				}
				else
				{
					switch (name)
					{	
						case "PortalId":
						
							if (value == null || value is System.Int32)
								this.PortalId = (System.Int32?)value;
							break;
						
						case "ClientId":
						
							if (value == null || value is System.Int32)
								this.ClientId = (System.Int32?)value;
							break;
						
						case "UserId":
						
							if (value == null || value is System.Int32)
								this.UserId = (System.Int32?)value;
							break;
						
						case "CreatedDate":
						
							if (value == null || value is System.DateTime)
								this.CreatedDate = (System.DateTime?)value;
							break;
						
						case "ModifiedDate":
						
							if (value == null || value is System.DateTime)
								this.ModifiedDate = (System.DateTime?)value;
							break;
					

						default:
							break;
					}
				}
			}
			else if(this.Row.Table.Columns.Contains(name))
			{
				this.Row[name] = value;
			}
			else
			{
				throw new Exception("SetProperty Error: '" + name + "' not found");
			}
		}
		
		
		/// <summary>
		/// Maps to DNNspot_LiveChat_Clients.PortalId
		/// </summary>
		virtual public System.Int32? PortalId
		{
			get
			{
				return base.GetSystemInt32(ClientMetadata.ColumnNames.PortalId);
			}
			
			set
			{
				base.SetSystemInt32(ClientMetadata.ColumnNames.PortalId, value);
			}
		}
		
		/// <summary>
		/// Maps to DNNspot_LiveChat_Clients.ClientId
		/// </summary>
		virtual public System.Int32? ClientId
		{
			get
			{
				return base.GetSystemInt32(ClientMetadata.ColumnNames.ClientId);
			}
			
			set
			{
				base.SetSystemInt32(ClientMetadata.ColumnNames.ClientId, value);
			}
		}
		
		/// <summary>
		/// Maps to DNNspot_LiveChat_Clients.UserId
		/// </summary>
		virtual public System.Int32? UserId
		{
			get
			{
				return base.GetSystemInt32(ClientMetadata.ColumnNames.UserId);
			}
			
			set
			{
				if(base.SetSystemInt32(ClientMetadata.ColumnNames.UserId, value))
				{
					this._UpToUserByUserId = null;
				}
			}
		}
		
		/// <summary>
		/// Maps to DNNspot_LiveChat_Clients.FirstName
		/// </summary>
		virtual public System.String FirstName
		{
			get
			{
				return base.GetSystemString(ClientMetadata.ColumnNames.FirstName);
			}
			
			set
			{
				base.SetSystemString(ClientMetadata.ColumnNames.FirstName, value);
			}
		}
		
		/// <summary>
		/// Maps to DNNspot_LiveChat_Clients.LastName
		/// </summary>
		virtual public System.String LastName
		{
			get
			{
				return base.GetSystemString(ClientMetadata.ColumnNames.LastName);
			}
			
			set
			{
				base.SetSystemString(ClientMetadata.ColumnNames.LastName, value);
			}
		}
		
		/// <summary>
		/// Maps to DNNspot_LiveChat_Clients.Email
		/// </summary>
		virtual public System.String Email
		{
			get
			{
				return base.GetSystemString(ClientMetadata.ColumnNames.Email);
			}
			
			set
			{
				base.SetSystemString(ClientMetadata.ColumnNames.Email, value);
			}
		}
		
		/// <summary>
		/// Maps to DNNspot_LiveChat_Clients.Ip
		/// </summary>
		virtual public System.String Ip
		{
			get
			{
				return base.GetSystemString(ClientMetadata.ColumnNames.Ip);
			}
			
			set
			{
				base.SetSystemString(ClientMetadata.ColumnNames.Ip, value);
			}
		}
		
		/// <summary>
		/// Maps to DNNspot_LiveChat_Clients.CreatedDate
		/// </summary>
		virtual public System.DateTime? CreatedDate
		{
			get
			{
				return base.GetSystemDateTime(ClientMetadata.ColumnNames.CreatedDate);
			}
			
			set
			{
				base.SetSystemDateTime(ClientMetadata.ColumnNames.CreatedDate, value);
			}
		}
		
		/// <summary>
		/// Maps to DNNspot_LiveChat_Clients.ModifiedDate
		/// </summary>
		virtual public System.DateTime? ModifiedDate
		{
			get
			{
				return base.GetSystemDateTime(ClientMetadata.ColumnNames.ModifiedDate);
			}
			
			set
			{
				base.SetSystemDateTime(ClientMetadata.ColumnNames.ModifiedDate, value);
			}
		}
		
		[CLSCompliant(false)]
		internal protected User _UpToUserByUserId;
		#endregion	

		#region String Properties


		[BrowsableAttribute( false )]
		public esStrings str
		{
			get
			{
				if (esstrings == null)
				{
					esstrings = new esStrings(this);
				}
				return esstrings;
			}
		}


		[Serializable]
		sealed public class esStrings
		{
			public esStrings(esClient entity)
			{
				this.entity = entity;
			}
			
	
			public System.String PortalId
			{
				get
				{
					System.Int32? data = entity.PortalId;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.PortalId = null;
					else entity.PortalId = Convert.ToInt32(value);
				}
			}
				
			public System.String ClientId
			{
				get
				{
					System.Int32? data = entity.ClientId;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.ClientId = null;
					else entity.ClientId = Convert.ToInt32(value);
				}
			}
				
			public System.String UserId
			{
				get
				{
					System.Int32? data = entity.UserId;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.UserId = null;
					else entity.UserId = Convert.ToInt32(value);
				}
			}
				
			public System.String FirstName
			{
				get
				{
					System.String data = entity.FirstName;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.FirstName = null;
					else entity.FirstName = Convert.ToString(value);
				}
			}
				
			public System.String LastName
			{
				get
				{
					System.String data = entity.LastName;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.LastName = null;
					else entity.LastName = Convert.ToString(value);
				}
			}
				
			public System.String Email
			{
				get
				{
					System.String data = entity.Email;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.Email = null;
					else entity.Email = Convert.ToString(value);
				}
			}
				
			public System.String Ip
			{
				get
				{
					System.String data = entity.Ip;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.Ip = null;
					else entity.Ip = Convert.ToString(value);
				}
			}
				
			public System.String CreatedDate
			{
				get
				{
					System.DateTime? data = entity.CreatedDate;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.CreatedDate = null;
					else entity.CreatedDate = Convert.ToDateTime(value);
				}
			}
				
			public System.String ModifiedDate
			{
				get
				{
					System.DateTime? data = entity.ModifiedDate;
					return (data == null) ? String.Empty : Convert.ToString(data);
				}

				set
				{
					if (value == null || value.Length == 0) entity.ModifiedDate = null;
					else entity.ModifiedDate = Convert.ToDateTime(value);
				}
			}
			

			private esClient entity;
		}
		#endregion

		#region Query Logic
		protected void InitQuery(esClientQuery query)
		{
			query.OnLoadDelegate = this.OnQueryLoaded;
			query.es2.Connection = ((IEntity)this).Connection;
		}

		[System.Diagnostics.DebuggerNonUserCode]
		protected bool OnQueryLoaded(DataTable table)
		{
			bool dataFound = this.PopulateEntity(table);

			if (this.RowCount > 1)
			{
				throw new Exception("esClient can only hold one record of data");
			}

			return dataFound;
		}
		#endregion
		
		[NonSerialized]
		private esStrings esstrings;
	}


	
	public partial class Client : esClient
	{

				
		#region MessageCollectionByClientId - Zero To Many
		/// <summary>
		/// Zero to Many
		/// Foreign Key Name - FK_DNNspot_LiveChat_Messages_DNNspot_LiveChat_Clients
		/// </summary>

		[XmlIgnore]
		public MessageCollection MessageCollectionByClientId
		{
			get
			{
				if(this._MessageCollectionByClientId == null)
				{
					this._MessageCollectionByClientId = new MessageCollection();
					this._MessageCollectionByClientId.es.Connection.Name = this.es.Connection.Name;
					this.SetPostSave("MessageCollectionByClientId", this._MessageCollectionByClientId);
				
					if(this.ClientId != null)
					{
						this._MessageCollectionByClientId.Query.Where(this._MessageCollectionByClientId.Query.ClientId == this.ClientId);
						this._MessageCollectionByClientId.Query.Load();

						// Auto-hookup Foreign Keys
						this._MessageCollectionByClientId.fks.Add(MessageMetadata.ColumnNames.ClientId, this.ClientId);
					}
				}

				return this._MessageCollectionByClientId;
			}
			
			set 
			{ 
				if (value != null) throw new Exception("'value' Must be null"); 
			 
				if (this._MessageCollectionByClientId != null) 
				{ 
					this.RemovePostSave("MessageCollectionByClientId"); 
					this._MessageCollectionByClientId = null;
					
				} 
			} 			
		}

		private MessageCollection _MessageCollectionByClientId;
		#endregion

				
		#region SessionCollectionByClientId - Zero To Many
		/// <summary>
		/// Zero to Many
		/// Foreign Key Name - FK_DNNspot_LiveChat_Sessions_DNNspot_LiveChat_Clients
		/// </summary>

		[XmlIgnore]
		public SessionCollection SessionCollectionByClientId
		{
			get
			{
				if(this._SessionCollectionByClientId == null)
				{
					this._SessionCollectionByClientId = new SessionCollection();
					this._SessionCollectionByClientId.es.Connection.Name = this.es.Connection.Name;
					this.SetPostSave("SessionCollectionByClientId", this._SessionCollectionByClientId);
				
					if(this.ClientId != null)
					{
						this._SessionCollectionByClientId.Query.Where(this._SessionCollectionByClientId.Query.ClientId == this.ClientId);
						this._SessionCollectionByClientId.Query.Load();

						// Auto-hookup Foreign Keys
						this._SessionCollectionByClientId.fks.Add(SessionMetadata.ColumnNames.ClientId, this.ClientId);
					}
				}

				return this._SessionCollectionByClientId;
			}
			
			set 
			{ 
				if (value != null) throw new Exception("'value' Must be null"); 
			 
				if (this._SessionCollectionByClientId != null) 
				{ 
					this.RemovePostSave("SessionCollectionByClientId"); 
					this._SessionCollectionByClientId = null;
					
				} 
			} 			
		}

		private SessionCollection _SessionCollectionByClientId;
		#endregion

				
		#region UpToUserByUserId - Many To One
		/// <summary>
		/// Many to One
		/// Foreign Key Name - FK_DNNspot_LiveChat_Clients_Users
		/// </summary>

		[XmlIgnore]
		public User UpToUserByUserId
		{
			get
			{
				if(this._UpToUserByUserId == null
					&& UserId != null					)
				{
					this._UpToUserByUserId = new User();
					this._UpToUserByUserId.es.Connection.Name = this.es.Connection.Name;
					this.SetPreSave("UpToUserByUserId", this._UpToUserByUserId);
					this._UpToUserByUserId.Query.Where(this._UpToUserByUserId.Query.UserID == this.UserId);
					this._UpToUserByUserId.Query.Load();
				}

				return this._UpToUserByUserId;
			}
			
			set
			{
				this.RemovePreSave("UpToUserByUserId");
				

				if(value == null)
				{
					this.UserId = null;
					this._UpToUserByUserId = null;
				}
				else
				{
					this.UserId = value.UserID;
					this._UpToUserByUserId = value;
					this.SetPreSave("UpToUserByUserId", this._UpToUserByUserId);
				}
				
			}
		}
		#endregion
		

		
		/// <summary>
		/// Used internally by the entity's hierarchical properties.
		/// </summary>
		protected override List<esPropertyDescriptor> GetHierarchicalProperties()
		{
			List<esPropertyDescriptor> props = new List<esPropertyDescriptor>();
			
			props.Add(new esPropertyDescriptor(this, "MessageCollectionByClientId", typeof(MessageCollection), new Message()));
			props.Add(new esPropertyDescriptor(this, "SessionCollectionByClientId", typeof(SessionCollection), new Session()));
		
			return props;
		}	
		
		/// <summary>
		/// Used internally for retrieving AutoIncrementing keys
		/// during hierarchical PreSave.
		/// </summary>
		protected override void ApplyPreSaveKeys()
		{
			if(!this.es.IsDeleted && this._UpToUserByUserId != null)
			{
				this.UserId = this._UpToUserByUserId.UserID;
			}
		}
		
		/// <summary>
		/// Used internally for retrieving AutoIncrementing keys
		/// during hierarchical PostSave.
		/// </summary>
		protected override void ApplyPostSaveKeys()
		{
			if(this._MessageCollectionByClientId != null)
			{
				foreach(Message obj in this._MessageCollectionByClientId)
				{
					if(obj.es.IsAdded)
					{
						obj.ClientId = this.ClientId;
					}
				}
			}
			if(this._SessionCollectionByClientId != null)
			{
				foreach(Session obj in this._SessionCollectionByClientId)
				{
					if(obj.es.IsAdded)
					{
						obj.ClientId = this.ClientId;
					}
				}
			}
		}
		
		/// <summary>
		/// Used internally for retrieving AutoIncrementing keys
		/// during hierarchical PostOneToOneSave.
		/// </summary>
		protected override void ApplyPostOneSaveKeys()
		{
		}
		
	}



	[Serializable]
	abstract public class esClientQuery : esDynamicQuery
	{
		override protected IMetadata Meta
		{
			get
			{
				return ClientMetadata.Meta();
			}
		}	
		

		public esQueryItem PortalId
		{
			get
			{
				return new esQueryItem(this, ClientMetadata.ColumnNames.PortalId, esSystemType.Int32);
			}
		} 
		
		public esQueryItem ClientId
		{
			get
			{
				return new esQueryItem(this, ClientMetadata.ColumnNames.ClientId, esSystemType.Int32);
			}
		} 
		
		public esQueryItem UserId
		{
			get
			{
				return new esQueryItem(this, ClientMetadata.ColumnNames.UserId, esSystemType.Int32);
			}
		} 
		
		public esQueryItem FirstName
		{
			get
			{
				return new esQueryItem(this, ClientMetadata.ColumnNames.FirstName, esSystemType.String);
			}
		} 
		
		public esQueryItem LastName
		{
			get
			{
				return new esQueryItem(this, ClientMetadata.ColumnNames.LastName, esSystemType.String);
			}
		} 
		
		public esQueryItem Email
		{
			get
			{
				return new esQueryItem(this, ClientMetadata.ColumnNames.Email, esSystemType.String);
			}
		} 
		
		public esQueryItem Ip
		{
			get
			{
				return new esQueryItem(this, ClientMetadata.ColumnNames.Ip, esSystemType.String);
			}
		} 
		
		public esQueryItem CreatedDate
		{
			get
			{
				return new esQueryItem(this, ClientMetadata.ColumnNames.CreatedDate, esSystemType.DateTime);
			}
		} 
		
		public esQueryItem ModifiedDate
		{
			get
			{
				return new esQueryItem(this, ClientMetadata.ColumnNames.ModifiedDate, esSystemType.DateTime);
			}
		} 
		
	}



    [System.Diagnostics.DebuggerDisplay("Count = {Count}")]
	[Serializable]
	[XmlType("ClientCollection")]
	public partial class ClientCollection : esClientCollection, IEnumerable<Client>
	{
		public ClientCollection()
		{

		}
		
		public static implicit operator List<Client>(ClientCollection coll)
		{
			List<Client> list = new List<Client>();
			
			foreach (Client emp in coll)
			{
				list.Add(emp);
			}
			
			return list;
		}
		
		#region Housekeeping methods
		override protected IMetadata Meta
		{
			get
			{
				return  ClientMetadata.Meta();
			}
		}
		
		
		
		override protected esDynamicQuery GetDynamicQuery()
		{
			if (this.query == null)
			{
				this.query = new ClientQuery();
				this.InitQuery(query);
			}
			return this.query;
		}
		
		override protected esEntity CreateEntityForCollection(DataRow row)
		{
			return new Client(row);
		}

		override protected esEntity CreateEntity()
		{
			return new Client();
		}
		
		
		#endregion


		[BrowsableAttribute( false )]
		public ClientQuery Query
		{
			get
			{
				if (this.query == null)
				{
					this.query = new ClientQuery();
					base.InitQuery(this.query);
				}

				return this.query;
			}
		}

		public void QueryReset()
		{
			this.query = null;
		}

		public bool Load(ClientQuery query)
		{
			this.query = query;
			base.InitQuery(this.query);
			return this.Query.Load();
		}
		
		public Client AddNew()
		{
			Client entity = base.AddNewEntity() as Client;
			
			return entity;
		}

		public Client FindByPrimaryKey(System.Int32 clientId)
		{
			return base.FindByPrimaryKey(clientId) as Client;
		}


		#region IEnumerable<Client> Members

		IEnumerator<Client> IEnumerable<Client>.GetEnumerator()
		{
			System.Collections.IEnumerable enumer = this as System.Collections.IEnumerable;
			System.Collections.IEnumerator iterator = enumer.GetEnumerator();

			while(iterator.MoveNext())
			{
				yield return iterator.Current as Client;
			}
		}

		#endregion
		
		private ClientQuery query;
	}


	/// <summary>
	/// Encapsulates the 'DNNspot_LiveChat_Clients' table
	/// </summary>

    [System.Diagnostics.DebuggerDisplay("Client ({ClientId})")]
	[Serializable]
	public partial class Client : esClient
	{
		public Client()
		{

		}
	
		public Client(DataRow row)
			: base(row)
		{

		}
		
		#region Housekeeping methods
		override protected IMetadata Meta
		{
			get
			{
				return ClientMetadata.Meta();
			}
		}
		
		
		
		override protected esClientQuery GetDynamicQuery()
		{
			if (this.query == null)
			{
				this.query = new ClientQuery();
				this.InitQuery(query);
			}
			return this.query;
		}
		#endregion
		



		[BrowsableAttribute( false )]
		public ClientQuery Query
		{
			get
			{
				if (this.query == null)
				{
					this.query = new ClientQuery();
					base.InitQuery(this.query);
				}

				return this.query;
			}
		}

		public void QueryReset()
		{
			this.query = null;
		}
		

		public bool Load(ClientQuery query)
		{
			this.query = query;
			base.InitQuery(this.query);
			return this.Query.Load();
		}
		
		private ClientQuery query;
	}



    [System.Diagnostics.DebuggerDisplay("LastQuery = {es.LastQuery}")]
	[Serializable]
		
	public partial class ClientQuery : esClientQuery
	{
		public ClientQuery()
		{

		}		
		
		public ClientQuery(string joinAlias)
		{
			this.es.JoinAlias = joinAlias;
		}	

        override protected string GetQueryName()
        {
            return "ClientQuery";
        }
		
			
	}


	[Serializable]
	public partial class ClientMetadata : esMetadata, IMetadata
	{
		#region Protected Constructor
		protected ClientMetadata()
		{
			_columns = new esColumnMetadataCollection();
			esColumnMetadata c;

			c = new esColumnMetadata(ClientMetadata.ColumnNames.PortalId, 0, typeof(System.Int32), esSystemType.Int32);
			c.PropertyName = ClientMetadata.PropertyNames.PortalId;
			c.NumericPrecision = 10;
			c.IsNullable = true;
			_columns.Add(c);
				
			c = new esColumnMetadata(ClientMetadata.ColumnNames.ClientId, 1, typeof(System.Int32), esSystemType.Int32);
			c.PropertyName = ClientMetadata.PropertyNames.ClientId;
			c.IsInPrimaryKey = true;
			c.IsAutoIncrement = true;
			c.NumericPrecision = 10;
			_columns.Add(c);
				
			c = new esColumnMetadata(ClientMetadata.ColumnNames.UserId, 2, typeof(System.Int32), esSystemType.Int32);
			c.PropertyName = ClientMetadata.PropertyNames.UserId;
			c.NumericPrecision = 10;
			c.IsNullable = true;
			_columns.Add(c);
				
			c = new esColumnMetadata(ClientMetadata.ColumnNames.FirstName, 3, typeof(System.String), esSystemType.String);
			c.PropertyName = ClientMetadata.PropertyNames.FirstName;
			c.CharacterMaxLength = 50;
			c.IsNullable = true;
			_columns.Add(c);
				
			c = new esColumnMetadata(ClientMetadata.ColumnNames.LastName, 4, typeof(System.String), esSystemType.String);
			c.PropertyName = ClientMetadata.PropertyNames.LastName;
			c.CharacterMaxLength = 50;
			c.IsNullable = true;
			_columns.Add(c);
				
			c = new esColumnMetadata(ClientMetadata.ColumnNames.Email, 5, typeof(System.String), esSystemType.String);
			c.PropertyName = ClientMetadata.PropertyNames.Email;
			c.CharacterMaxLength = 50;
			c.IsNullable = true;
			_columns.Add(c);
				
			c = new esColumnMetadata(ClientMetadata.ColumnNames.Ip, 6, typeof(System.String), esSystemType.String);
			c.PropertyName = ClientMetadata.PropertyNames.Ip;
			c.CharacterMaxLength = 50;
			c.IsNullable = true;
			_columns.Add(c);
				
			c = new esColumnMetadata(ClientMetadata.ColumnNames.CreatedDate, 7, typeof(System.DateTime), esSystemType.DateTime);
			c.PropertyName = ClientMetadata.PropertyNames.CreatedDate;
			c.HasDefault = true;
			c.Default = @"(getdate())";
			c.IsNullable = true;
			_columns.Add(c);
				
			c = new esColumnMetadata(ClientMetadata.ColumnNames.ModifiedDate, 8, typeof(System.DateTime), esSystemType.DateTime);
			c.PropertyName = ClientMetadata.PropertyNames.ModifiedDate;
			c.HasDefault = true;
			c.Default = @"(getdate())";
			c.IsNullable = true;
			_columns.Add(c);
				
		}
		#endregion	
	
		static public ClientMetadata Meta()
		{
			return meta;
		}	
		
		public Guid DataID
		{
			get { return base._dataID; }
		}	
		
		public bool MultiProviderMode
		{
			get { return false; }
		}		

		public esColumnMetadataCollection Columns
		{
			get	{ return base._columns; }
		}
		
		#region ColumnNames
		public class ColumnNames
		{ 
			 public const string PortalId = "PortalId";
			 public const string ClientId = "ClientId";
			 public const string UserId = "UserId";
			 public const string FirstName = "FirstName";
			 public const string LastName = "LastName";
			 public const string Email = "Email";
			 public const string Ip = "Ip";
			 public const string CreatedDate = "CreatedDate";
			 public const string ModifiedDate = "ModifiedDate";
		}
		#endregion	
		
		#region PropertyNames
		public class PropertyNames
		{ 
			 public const string PortalId = "PortalId";
			 public const string ClientId = "ClientId";
			 public const string UserId = "UserId";
			 public const string FirstName = "FirstName";
			 public const string LastName = "LastName";
			 public const string Email = "Email";
			 public const string Ip = "Ip";
			 public const string CreatedDate = "CreatedDate";
			 public const string ModifiedDate = "ModifiedDate";
		}
		#endregion	

		public esProviderSpecificMetadata GetProviderMetadata(string mapName)
		{
			MapToMeta mapMethod = mapDelegates[mapName];

			if (mapMethod != null)
				return mapMethod(mapName);
			else
				return null;
		}
		
		#region MAP esDefault
		
		static private int RegisterDelegateesDefault()
		{
			// This is only executed once per the life of the application
			lock (typeof(ClientMetadata))
			{
				if(ClientMetadata.mapDelegates == null)
				{
					ClientMetadata.mapDelegates = new Dictionary<string,MapToMeta>();
				}
				
				if (ClientMetadata.meta == null)
				{
					ClientMetadata.meta = new ClientMetadata();
				}
				
				MapToMeta mapMethod = new MapToMeta(meta.esDefault);
				mapDelegates.Add("esDefault", mapMethod);
				mapMethod("esDefault");
			}
			return 0;
		}			

		private esProviderSpecificMetadata esDefault(string mapName)
		{
			if(!_providerMetadataMaps.ContainsKey(mapName))
			{
				esProviderSpecificMetadata meta = new esProviderSpecificMetadata();
				

				meta.AddTypeMap("PortalId", new esTypeMap("int", "System.Int32"));
				meta.AddTypeMap("ClientId", new esTypeMap("int", "System.Int32"));
				meta.AddTypeMap("UserId", new esTypeMap("int", "System.Int32"));
				meta.AddTypeMap("FirstName", new esTypeMap("nvarchar", "System.String"));
				meta.AddTypeMap("LastName", new esTypeMap("nvarchar", "System.String"));
				meta.AddTypeMap("Email", new esTypeMap("nvarchar", "System.String"));
				meta.AddTypeMap("Ip", new esTypeMap("nvarchar", "System.String"));
				meta.AddTypeMap("CreatedDate", new esTypeMap("datetime", "System.DateTime"));
				meta.AddTypeMap("ModifiedDate", new esTypeMap("datetime", "System.DateTime"));			
				
				
				
				ProviderConfiguration providerConfiguration = ProviderConfiguration.GetProviderConfiguration("data");
				Provider provider = (Provider)providerConfiguration.Providers[providerConfiguration.DefaultProvider];

				string objectQualifier = provider.Attributes["objectQualifier"];

				if ((objectQualifier != string.Empty) && (objectQualifier.EndsWith("_") == false))
				{
					objectQualifier += "_";
				}

				if (objectQualifier != string.Empty)
				{
					meta.Source = objectQualifier + "DNNspot_LiveChat_Clients";
					meta.Destination = objectQualifier + "DNNspot_LiveChat_Clients";
					
					meta.spInsert = objectQualifier + "proc_DNNspot_LiveChat_ClientsInsert";				
					meta.spUpdate = objectQualifier + "proc_DNNspot_LiveChat_ClientsUpdate";		
					meta.spDelete = objectQualifier + "proc_DNNspot_LiveChat_ClientsDelete";
					meta.spLoadAll = objectQualifier + "proc_DNNspot_LiveChat_ClientsLoadAll";
					meta.spLoadByPrimaryKey = objectQualifier + "proc_DNNspot_LiveChat_ClientsLoadByPrimaryKey";
				}
				else
				{
					meta.Source = "DNNspot_LiveChat_Clients";
					meta.Destination = "DNNspot_LiveChat_Clients";
									
					meta.spInsert = "proc_DNNspot_LiveChat_ClientsInsert";				
					meta.spUpdate = "proc_DNNspot_LiveChat_ClientsUpdate";		
					meta.spDelete = "proc_DNNspot_LiveChat_ClientsDelete";
					meta.spLoadAll = "proc_DNNspot_LiveChat_ClientsLoadAll";
					meta.spLoadByPrimaryKey = "proc_DNNspot_LiveChat_ClientsLoadByPrimaryKey";
				}
				
				
				this._providerMetadataMaps["esDefault"] = meta;
			}
			
			return this._providerMetadataMaps["esDefault"];
		}

		#endregion

		static private ClientMetadata meta;
		static protected Dictionary<string, MapToMeta> mapDelegates;
		static private int _esDefault = RegisterDelegateesDefault();
	}
}
